package com.lg.product.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.lg.product.entity.SpecGroup;
import com.lg.product.entity.SpecParam;
import com.lg.product.mapper.SpecGroupMapper;
import com.lg.product.mapper.SpecParamMapper;
import com.lg.product.service.ISpecGroupService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.lg.product.service.ISpecParamService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 规格参数的分组表，每个商品分类下有多个规格参数组 服务实现类
 * </p>
 *
 * @author song
 * @since 2020-07-22
 */
@Service
public class SpecGroupServiceImpl extends ServiceImpl<SpecGroupMapper, SpecGroup> implements ISpecGroupService {

    @Autowired
    private ISpecParamService iSpecParamService;

    /**
     *
     * 规格 分组 查询
     * @return
     */
    public List<SpecGroup> groupListCid(Integer cid){

        List<SpecGroup> specGroups = baseMapper.groupListCid(cid);
        specGroups.forEach(res->{
            List<SpecParam> specParams = iSpecParamService.selectById(res.getId().intValue());
                res.setParams(specParams);
        });
        return specGroups;
    }

    /**
     * 规格 分组 添加
     * @return
     */
    public int addSpecGroup(SpecGroup specGroup){
        int i = baseMapper.insert(specGroup);
        return i;
    }

    /**
     * 规格 分组 删除
     * @return
     */
    public int deleteSpecGroup(Integer id){
        int i = baseMapper.deleteById(id);
        return i;
    }

    /**
     * 规格 分组 根据cid删除
     * @param cid
     * @return
     */
    @Override
    public Long deleteGroupCid(Long cid) {
        Long aLong = baseMapper.deleteGroupCid(cid);
        return aLong;
    }


}
